﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using HiLand.Utility.DataBase;

namespace HySoft.Cash.Structure
{
    [Serializable]
    public class TStatementDT
    {
        public static TStatementDT ConvertFrom(DataRow row)
        {
            TStatementDT entity = new TStatementDT();
            if (row != null)
            {
                if (DataRowHelper.IsExistField(row, "guid") && Convert.IsDBNull(row["guid"]) == false)
                {
                    entity.guid = new Guid(Convert.ToString(row["guid"]));
                }
                if (DataRowHelper.IsExistField(row, "ID") && Convert.IsDBNull(row["ID"]) == false)
                {
                    entity.id = Convert.ToInt32(row["ID"]);
                }
                if (DataRowHelper.IsExistField(row, "memo") && Convert.IsDBNull(row["memo"]) == false)
                {
                    entity.memo = Convert.ToString(row["memo"]);
                }
                if (DataRowHelper.IsExistField(row, "orgid") && Convert.IsDBNull(row["orgid"]) == false)
                {
                    entity.orgid = Convert.ToInt32(row["orgid"]);
                }
                if (DataRowHelper.IsExistField(row, "sendstatus") && Convert.IsDBNull(row["sendstatus"]) == false)
                {
                    entity.sendstatus = (StatementSendStatuses)Convert.ToInt32(row["sendstatus"]);
                }
                if (DataRowHelper.IsExistField(row, "statementdate") && Convert.IsDBNull(row["statementdate"]) == false)
                {
                    entity.statementdate = Convert.ToDateTime(row["statementdate"]);
                }
                if (DataRowHelper.IsExistField(row, "status") && Convert.IsDBNull(row["status"]) == false)
                {
                    entity.status = (StatementStatuses)Convert.ToInt32(row["status"]);
                }
                if (DataRowHelper.IsExistField(row, "totalinterest") && Convert.IsDBNull(row["totalinterest"]) == false)
                {
                    entity.totalinterest = Convert.ToDecimal(row["totalinterest"]);
                }
                if (DataRowHelper.IsExistField(row, "totalinterestpaid") && Convert.IsDBNull(row["totalinterestpaid"]) == false)
                {
                    entity.totalinterestpaid = Convert.ToDecimal(row["totalinterestpaid"]);
                }
                if (DataRowHelper.IsExistField(row, "totallateinterestcharges") && Convert.IsDBNull(row["totallateinterestcharges"]) == false)
                {
                    entity.totallateinterestcharges = Convert.ToDecimal(row["totallateinterestcharges"]);
                }
                if (DataRowHelper.IsExistField(row, "totallateinterestchargespaid") && Convert.IsDBNull(row["totallateinterestchargespaid"]) == false)
                {
                    entity.totallateinterestchargespaid = Convert.ToDecimal(row["totallateinterestchargespaid"]);
                }
                if (DataRowHelper.IsExistField(row, "totalpenalty") && Convert.IsDBNull(row["totalpenalty"]) == false)
                {
                    entity.totalpenalty = Convert.ToDecimal(row["totalpenalty"]);
                }
                if (DataRowHelper.IsExistField(row, "totalpenaltypaid") && Convert.IsDBNull(row["totalpenaltypaid"]) == false)
                {
                    entity.totalpenaltypaid = Convert.ToDecimal(row["totalpenaltypaid"]);
                }
                if (DataRowHelper.IsExistField(row, "totalprincipal") && Convert.IsDBNull(row["totalprincipal"]) == false)
                {
                    entity.totalprincipal = Convert.ToDecimal(row["totalprincipal"]);
                }
                if (DataRowHelper.IsExistField(row, "totalprincipalpaid") && Convert.IsDBNull(row["totalprincipalpaid"]) == false)
                {
                    entity.totalprincipalpaid = Convert.ToDecimal(row["totalprincipalpaid"]);
                }
                if (DataRowHelper.IsExistField(row, "LastCreditBalance") && Convert.IsDBNull(row["LastCreditBalance"]) == false)
                {
                    entity.LastCreditBalance = Convert.ToDecimal(row["LastCreditBalance"]);
                }

                if (DataRowHelper.IsExistField(row, "LastFeeBalance") && Convert.IsDBNull(row["LastFeeBalance"]) == false)
                {
                    entity.LastFeeBalance = Convert.ToDecimal(row["LastFeeBalance"]);
                }

                if (DataRowHelper.IsExistField(row, "OrgName") && Convert.IsDBNull(row["OrgName"]) == false)
                {
                    entity.OrgName = Convert.ToString(row["OrgName"]);
                }

                if (DataRowHelper.IsExistField(row, "PreferredEmail") && Convert.IsDBNull(row["PreferredEmail"]) == false)
                {
                    entity.PreferredEmail = Convert.ToString(row["PreferredEmail"]);
                }
            }

            return entity;
        }



        public static TStatementDT ConvertFrom(IDataReader reader)
        {
            TStatementDT entity = new TStatementDT();
            if (reader != null)
            {
                entity.guid = new Guid(Convert.ToString(reader["guid"]));
                entity.id = Convert.ToInt32(reader["ID"]);
                entity.memo = Convert.ToString(reader["memo"]);
                entity.orgid = Convert.ToInt32(reader["orgid"]);
                entity.sendstatus = (StatementSendStatuses)Convert.ToInt32(reader["sendstatus"]);
                entity.statementdate = Convert.ToDateTime(reader["statementdate"]);
                entity.status = (StatementStatuses)Convert.ToInt32(reader["status"]);
                entity.totalinterest = Convert.ToDecimal(reader["totalinterest"]);
                entity.totalinterestpaid = Convert.ToDecimal(reader["totalinterestpaid"]);
                entity.totallateinterestcharges = Convert.ToDecimal(reader["totallateinterestcharges"]);
                entity.totallateinterestchargespaid = Convert.ToDecimal(reader["totallateinterestchargespaid"]);
                entity.totalpenalty = Convert.ToDecimal(reader["totalpenalty"]);
                entity.totalpenaltypaid = Convert.ToDecimal(reader["totalpenaltypaid"]);
                entity.totalprincipal = Convert.ToDecimal(reader["totalprincipal"]);
                entity.totalprincipalpaid = Convert.ToDecimal(reader["totalprincipalpaid"]);

                if (DataReaderHelper.IsExistField(reader, "LastCreditBalance") && Convert.IsDBNull(reader["LastCreditBalance"]) == false)
                {
                    entity.LastCreditBalance = Convert.ToDecimal(reader["LastCreditBalance"]);
                }

                if (DataReaderHelper.IsExistField(reader, "LastFeeBalance") && Convert.IsDBNull(reader["LastFeeBalance"]) == false)
                {
                    entity.LastFeeBalance = Convert.ToDecimal(reader["LastFeeBalance"]);
                }
            }

            return entity;
        }



        public static string allFields = "*,(TotalPrincipal+ TotalInterest + TotalPenalty+ TotalLateInterestCharges) as TotalBalanceNeed,(TotalPrincipalPaid+ TotalInterestPaid+ TotalPenaltyPaid+ TotalLateInterestChargesPaid) as TotalBalancePaid";

        private int id;
        private System.Guid guid;
        private int orgid;
        private System.DateTime statementdate;
        private string memo;
        private decimal totalprincipal;
        private decimal totalinterest;
        private decimal totalpenalty;
        private decimal totallateinterestcharges;
        private decimal totalprincipalpaid;
        private decimal totalinterestpaid;
        private decimal totalpenaltypaid;
        private decimal totallateinterestchargespaid;
        private StatementStatuses status;
        private StatementSendStatuses sendstatus;


        private decimal lastCreditBalance;
        private decimal lastFeeBalance;

        private string orgName = string.Empty;
        private string preferredEmail = string.Empty;



        /// <summary>
        /// 
        /// </summary>
        public int ID
        {
            set { id = value; }
            get { return id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public System.Guid Guid
        {
            set { guid = value; }
            get { return guid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int OrgID
        {
            set { orgid = value; }
            get { return orgid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public System.DateTime StatementDate
        {
            set { statementdate = value; }
            get { return statementdate; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Memo
        {
            set { memo = value; }
            get { return memo; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalPrincipal
        {
            set { totalprincipal = value; }
            get { return totalprincipal; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalInterest
        {
            set { totalinterest = value; }
            get { return totalinterest; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalPenalty
        {
            set { totalpenalty = value; }
            get { return totalpenalty; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalLateInterestCharges
        {
            set { totallateinterestcharges = value; }
            get { return totallateinterestcharges; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalPrincipalPaid
        {
            set { totalprincipalpaid = value; }
            get { return totalprincipalpaid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalInterestPaid
        {
            set { totalinterestpaid = value; }
            get { return totalinterestpaid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalPenaltyPaid
        {
            set { totalpenaltypaid = value; }
            get { return totalpenaltypaid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal TotalLateInterestChargesPaid
        {
            set { totallateinterestchargespaid = value; }
            get { return totallateinterestchargespaid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public StatementStatuses Status
        {
            set { status = value; }
            get { return status; }
        }
        /// <summary>
        /// 
        /// </summary>
        public StatementSendStatuses SendStatus
        {
            set { sendstatus = value; }
            get { return sendstatus; }
        }

        public decimal LastCreditBalance
        {
            get { return this.lastCreditBalance; }
            set { this.lastCreditBalance = value; }
        }

        public decimal LastFeeBalance
        {
            get { return this.lastFeeBalance; }
            set { this.lastFeeBalance = value; }
        }

        public decimal TotalBalanceNeed
        {
            get
            {
                return this.totalinterest + this.totallateinterestcharges + this.totalpenalty + this.totalprincipal;
            }
        }

        public decimal TotalBalancePaid
        {
            get
            {
                return this.totalinterestpaid + this.totallateinterestchargespaid + this.totalpenaltypaid + this.totalprincipalpaid;
            }
        }

        public string OrgName
        {
            get { return this.orgName; }
            set { this.orgName = value; }
        }
        public string PreferredEmail
        {
            get { return this.preferredEmail; }
            set { this.preferredEmail = value; }
        }
    }

    public enum StatementStatuses
    {
        Normal = 0,
    }

    public enum StatementSendStatuses
    {
        NeedSend = 0,//需要发送
        NeedReSend = 10,//需要重新发送
        Sent = 20,//已发送
    }
}
